Skip to content

Conversation

mmaymo
Copy link
Collaborator

@mmaymo mmaymo commented Sep 9, 2025

Add React component architecture for Mollie checkout blocks

  • Add PHPCS exclusions for non-PHP asset files
  • Implement payment component factory pattern for method-specific content rendering
  • Add reusable field components (phone, birthdate, company, credit card)
  • Create payment method components for credit card, Billie, In3, and Riverty
  • Add HOC for Redux store connection and centralized payment processing

This PR is based on PIWOO-761-redux-store
(Some logs might still be there, will remove in the last round)

@mmaymo mmaymo changed the title Block components and hoc (PIWOO-761) 2 - Block components and hoc (PIWOO-761) Sep 15, 2025

return (
<div className="custom-input">
<label htmlFor="billing-birthdate">{ label }</label>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jsx tag isn't closed properly here, right? Also this can probably be a short tag

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, no, I think is closed right, is not a void element, but I will take a look at all the other elements around

@@ -0,0 +1,19 @@
export const BirthdateField = ( { label, value, onChange } ) => {
const handleChange = ( e ) => onChange( e.target.value );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be an optimization to declare this function outside of the component (so it does not get reinitialized everytime we re-render)

As an alternative, perhaps look into useCallback https://react.dev/reference/react/useCallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked some docs, cause makes sense what you say, but if I understood right, declaring the function outside or using useCallback only helps if we pass it down to children or use it as a dependency in an effect. In our case the handler is only attached to a native (not a React child), so its identity doesn’t cause any extra renders. And if taking out I would need a way to pass the prop to that function. But I will add a new task to check in the parent components if the child components can be memoized.

Copy link
Collaborator

@Biont Biont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good already! I left some comments and I believe a few things can be improved

export const Label = ( { item } ) => {
return (
<>
<div dangerouslySetInnerHTML={ { __html: item.label } } />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we are expecting markup within item.label ? Otherwise I wonder why we aren't simply passing it into the content

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but there is no need to pass markup really, now we pass only data I've updated it

Comment on lines +10 to +11
const { useEffect } = wp.element;
const { useSelect } = wp.data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be imports - at the very least they should not be assigned in the render function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I will tackle this in another PR

billing_birthdate: inputBirthdate,
cardToken: '',
};
const tokenVal = jQuery( '.mollie-components > input' ).val();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is all we need jQuery for, should we not think about doing it in vanilla JS instead?

A more thorough solution would be to expose this type of data through te redux store and then consume it via withSelect and/or a higher-order-component

Copy link
Collaborator Author

@mmaymo mmaymo Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, using the token from the store is done in a later PR but I've also expanded on the use of the store there after your suggestion, I think I can also use in the payment fields, I will update those as well. Removing jQuery is also a job started later but I will take a look in case i missed somewhere. Thanks!

@mmaymo mmaymo requested a review from Biont September 18, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants